import axios from "../utils/http";
import path from "./path";

const api = {



    getProductsByName(name) {
        return axios.get(path.baseUrl + path.search + name);
    },
    //我的订单————————————————————————————————————
    getOrdersByUserid(user_id){
        return axios.get(path.baseUrl + path.orders + user_id);
    },
    getOrderByOrderId(order_id){
        return axios.get(path.baseUrl + path.orders +'detail/'+ order_id);
    },
    //我的喜欢
    getFavoriteByName(username) {
        return axios.get(path.baseUrl + path.account_favorite + username);
    },


    //--------------购物车-----------------
    getCartListByName(username){
        return axios.get(path.baseUrl+path.cart+username);
    },
    deleteCartItem(delete_form){
        return axios.delete(path.baseUrl + path.cart + path.cartItem,{
            data: delete_form,
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    },

    //删除要加请求头config，put不要加，put加了又不管用了，不懂
    updateQuantityByItemId(update_form){
        return axios.put(path.baseUrl+ path.cart+ path.cartItem,update_form)
    },
    cartToOrder(cartFormAndAccount){
        return axios.post(path.baseUrl+path.orders+'newOrder',cartFormAndAccount, {
            headers: {
                'Content-Type': 'application/json'
            }
        })
    },
    confirmOrder(form){
        return axios.post(path.baseUrl+path.orders+'confirmOrder',form)
    },

    confirmAlipay(form){
        return axios.post(path.baseUrl+path.orders+'updatePayStatus',form,{
            headers: {
                'Content-Type': 'application/json'
            }
        })
    },


  //商品
    getProductsByCategory(category) {
        return axios.get(path.baseUrl + path.category + category);
    },

    getItemsByProductId(productId){
        return axios.get(path.baseUrl + path.product + productId);
    },

     getItemById(itemId){
         return axios.get(path.baseUrl + path.item + itemId);
     },

    // addToCart(username,itemId) {
    //     return axios.post(path.baseUrl + path.cart+ 'cartItem',username,itemId, {
    //         headers: {
    //             'Content-Type': 'application/json'
    //         }
    //     });
    // },


     //支付宝
    getAlipay(price){
        return axios.get(path.baseUrl + '/alipay/pay/' + price);
    },

}



export default api
